package org.feng.controller;

import org.feng.upload.build.ResourceBuilder;
import org.feng.pojo.Result;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author 冯帅
 * @des TODO
 * @date 2021/11/30 15:47
 * @email 15612509687@163.com
 */
@RestController
@RequestMapping( "/system/upload")
@AllArgsConstructor
@Api(value = "上传", tags = "上传")
public class UploadController {

    private final ResourceBuilder resourceBuilder;

    @PostMapping("/file")
    public Result<String> upload(@RequestParam MultipartFile file) throws IOException {
        return Result.success(resourceBuilder.build().putFile(file.getInputStream(), file.getOriginalFilename(), false));
    }

}
